import request from ".";


interface ApiResponse<T = unknown> {
    code: number,
    data: T,
    message: string
}

export const getNewsPool = (params: { current?: number, currentSize?: number, isSelect?: number }) => {
    return request.get('/news/newsList', { params })
}

export const getNewsDetail = (id: number) => {
    return request.post('/news/selectById', { id })
}


export const getSelectAll = () => {
    return request.post('/news/selectAllCountClassReal')
}


export const getSelectPublish = (params: { current: number, currentSize: number, putState: number }) => {
    return request.post('/news/selectPublish', params)
}



// export const updataList = <T>(params: { id: number, [key: string]: unknown }) => {
//     return request.post('/news/updateNews', params) as Promise<ApiResponse<T>>
// }


export const getReleaseList = <T>() => {
    return request.post('/news/releaseList') as Promise<ApiResponse<T>>
}

interface News {
    id?: number,
    newsTitle?: string,
    title?: string,
    abstractReal: string,
    classReal: number,
    classModel?: string,
    newsSource?: string,
    newsTime?: number,
    coverImage?: string,
    isSelect?: number,
    addMode: number,
    siteName?: string,
    opPerson?: string,
    createTime?: string,
    pubTime?: string,
    isPublish?: number,
    markContent?: string,
    sourceUrl?: string,
}
export const createNews = <T>(data: Omit<News, 'id'>) => {
    return request.post('/news/insertNews', data) as Promise<ApiResponse<T>>
}

export const updateNews = <T>(data: Partial<News> & { id: number }) => {
    return request.post('/news/updateNews', data) as Promise<ApiResponse<T>>
}


export const refresh = (params: { refresh_token: string}) => {
    return request.post('/news/refresh',params)
}



interface IPublish{
    waitPubTime?: string,
    issueTitle: string,
    issueCoverImage: string,
    issueDescription: string,
    issuePublisher: string,
}
export const newPublishReleaseList = <T>(data: IPublish) => {
    return request.post('/news/publishReleaseList', data) as Promise<ApiResponse<T>>
}



export const newIssueList=<T>(params:{current:number,currentSize:number})=>{
    return request.post('/news/issueList',params) as Promise<ApiResponse<T>>
}